package ocean.chinacraft.common.world.item.tool;

import ocean.chinacraft.common.config.GroupDefine;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityPredicate;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

/**
 * 禅杖
 *
 * @author zhang
 * @since 2021/12/3
 */
public class ZenStick extends Item {

    private final EntityPredicate attackTargeting = (new EntityPredicate()).range(64.0D);

    public ZenStick() {
        super(new Properties().tab(GroupDefine.CHINACRAFT_TOOL).stacksTo(1));
    }

    @Override
    public boolean onLeftClickEntity(ItemStack stack, PlayerEntity player, Entity entity) {
        if (entity.isAlive()) {
            LivingEntity livingEntity = (LivingEntity) entity;
            livingEntity.setHealth(livingEntity.getHealth() + 1);
        }
        return true;
    }

//    @Override
//    public ActionResult<ItemStack> use(@Nonnull World world, @Nonnull PlayerEntity player, @Nonnull Hand hand) {
//        ItemStack inHand = player.getItemInHand(hand);
//        if (player.isAlive()) {
//            List<PlayerEntity> players = findNear(player, 20, 20);
//            for (PlayerEntity entity : players) {
//                entity.setHealth(entity.getHealth() + 5);
//            }
//            return ActionResult.success(inHand);
//        }
//        return ActionResult.pass(inHand);
//    }
//
//    public List<PlayerEntity> findNear(PlayerEntity player, double d0, double d1) {
//        double x = player.getX();
//        double y = player.getY();
//        double z = player.getZ();
//        return player.level.getNearbyPlayers(attackTargeting, player, new AxisAlignedBB(x, y, z,
//                x + d0, y + d1, z + d0));
//    }
}
